package com.example.myapplication3;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication3.bean.Beijing;
import com.example.myapplication3.bean.Student1;
import com.example.myapplication3.bean.Student2;
import com.example.myapplication3.bean.Student3;
import com.example.myapplication3.bean.Student4;
import com.example.myapplication3.interfaces.IHome;
import com.example.myapplication3.persenter.HomePersenter;

import java.util.ArrayList;

public class Main2Activity extends AppCompatActivity implements IHome.View {

    private RecyclerView rv;
    private ArrayList<Beijing.ResultBean> resultBeans;
    private Adapter2 adapter2;
    private HomePersenter homePersenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        initView();
        initData();
    }

    private void initData() {
        homePersenter = new HomePersenter(this);
        homePersenter.getCity5();
    }

    private void initView() {
        rv = (RecyclerView) findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.addItemDecoration(new DividerItemDecoration(this,1));
        resultBeans = new ArrayList<>();
        adapter2 = new Adapter2(resultBeans, this);
        rv.setAdapter(adapter2);

        adapter2.setOnClickListener(new Adapter2.OnClickListener() {
            @Override
            public void ClickListener(int position) {
                Intent intent = new Intent();
                intent.putExtra("name",resultBeans.get(position).getCity());
                setResult(78,intent);
                finish();
            }
        });

    }

    @Override
    public void getStudent1(Student1 result) {

    }

    @Override
    public void getStudent2(Student2 result) {

    }

    @Override
    public void getStudent3(Student3 result) {

    }

    @Override
    public void getStudent4(Student4 result) {

    }

    @Override
    public void getStudent5(Beijing result) {

       if (result!=null){
           Log.e("TAG555",result.getResult().get(0).getCity());
           resultBeans.addAll(result.getResult());
           adapter2.notifyDataSetChanged();
       } else {
           Log.e("TAG555","没有解析出来数据");
       }

    }

    @Override
    public void tips(String tip) {

    }

    @Override
    public void loading(int visible) {

    }
}
